package io.renren.vo;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import io.renren.entity.SeatApplicationEntity;
import lombok.Data;
import org.springframework.beans.BeanUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * 工位预定列表
 *
 * @author 1
 * @email 1@2.com
 * @date 2021-08-19 11:56:03
 */
@Data
public class SeatApplicationVo {

    /**
     *
     */
    private Long id;
    /**
     * 工位id
     */
    private Long seatId;
    /**
     * 工位编号
     */
    private String seatCode;
    /**
     * 预定工位的员工id
     */
    private Long employeeId;
    /**
     * 预定状态
     */
    private String state;
    /**
     * 预定日期
     */
    private String bookDate;
    /**
     * 预定开始时间
     */
    private String bookStratTime;
    /**
     * 预定结束时间
     */
    private String bookEndTime;
    /**
     * 姓名
     */
    private String employeeName;

    public static SeatApplicationVo convertFor(SeatApplicationEntity seatApplicationEntity) {
        SeatApplicationVo vo = new SeatApplicationVo();
        if (seatApplicationEntity != null) {
            BeanUtils.copyProperties(seatApplicationEntity, vo);
//            String state = "未开始";
//            if (DateUtil.compare(seatApplicationEntity.getStartTime(), new Date()) <= 0 && DateUtil.compare(seatApplicationEntity.getEndTime(), new Date()) > 0) {
//                state = "使用中";
//            }
//            if (DateUtil.compare(seatApplicationEntity.getEndTime(), new Date()) <= 0) {
//                state = "已结束";
//            }


            vo.setBookDate(DateUtil.format(seatApplicationEntity.getStartTime(), DatePattern.CHINESE_DATE_FORMAT));
            vo.setBookStratTime(DateUtil.format(seatApplicationEntity.getStartTime(), DatePattern.NORM_TIME_PATTERN));
            vo.setBookEndTime(DateUtil.format(seatApplicationEntity.getEndTime(), DatePattern.NORM_TIME_PATTERN));
        }
        return vo;
    }

    public static List<SeatApplicationVo> convertFor(List<SeatApplicationEntity> seatApplicationEntitys) {
        List<SeatApplicationVo> vos = new ArrayList<>();
        if (CollectionUtil.isNotEmpty(seatApplicationEntitys)) {
            for (SeatApplicationEntity seatApplicationEntity : seatApplicationEntitys) {
                vos.add(convertFor(seatApplicationEntity));
            }
        }
        return vos;
    }


}
